package Tree;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Set;
import java.util.TreeSet;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 38917
 * Date: 2025-04-01
 * Time: 13:14
 */
public class MyTreeSet {
    public static void main(String[] args) {
        Set<String> treeSet = new TreeSet<>();
        //add
        //不能插入null
        treeSet.add("A");
        //addAll
        Collection<String> array1 = new ArrayList<>();
        array1.add("B");
        array1.add("C");
        array1.add("D");
        array1.add("E");
        treeSet.addAll(array1);
        //remove和contains
        treeSet.remove("E");
        System.out.println(treeSet.contains("E"));//输出false
        //removeAll
        Collection<String> array2 = new ArrayList<>();
        array2.add("D");
        array2.add("九转苍翎");
        //当array2中的元素有一部分在treeSet能找到,有一部分在treeSet不存在时也会返回true，并且把"D"移除
        System.out.println(treeSet.removeAll(array2));//true
        //但凡有一个不包含就返回false
        Collection<String> array3 = new ArrayList<>();
        array3.add("A");
        array3.add("九转苍翎");
        System.out.println(treeSet.containsAll(array3));//输出false
        //size
        System.out.println(treeSet.size());//输出3
        //isEmpty
        System.out.println(treeSet.isEmpty());//输出false
        //clear
        treeSet.clear();
    }
}
